/* 
 *	Copyright (C) 2009-2010 miaohua
 *	http://code.google.com/p/lrcshower/
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */

#pragma once
#include "afxwin.h"
#include "afxcmn.h"
#include "ListCtrlEx.h"
#include "MenuButton.h"


// CPlayListDlg dialog
// This dialog is used to play / edit / add / delete playlist
class CPlayListDlg : public CDialog
{
	DECLARE_DYNAMIC(CPlayListDlg)

public:
	CPlayListDlg(CWnd* pParent = NULL);   // standard constructor
	virtual ~CPlayListDlg();

    // Insert one song to GUI song list
    void InsertOneSong(CString SongPath);
    // Get current selected playlist index
    int GetPLCurSel();
    // Dialog Data
	enum { IDD = IDD_PLAYLIST_DLG };

protected:
    virtual BOOL OnInitDialog();
    afx_msg void OnCbnSelchangePlayListSel();
    // Menu button message handler
    // Play mode button
    afx_msg void OnSinglePlay();
    afx_msg void OnSingleLoop();
    afx_msg void OnMultiSeq();
    afx_msg void OnMultiLoop();
    afx_msg void OnMulitRand();
    // Edit playlist button
    afx_msg void OnAddFile();
    afx_msg void OnAddFolder();
    afx_msg void OnLocalSearch();
    afx_msg void OnDelSelFile();
    afx_msg void OnDelDupFile();
    afx_msg void OnDelErrFile();
    afx_msg void OnDelAllFile();
    // Operate playlist
    afx_msg void OnCreatePL();
    afx_msg void OnOpenPL();
    afx_msg void OnAddPL();
    afx_msg void OnSavePL();
    afx_msg void OnDelPL();
    // Message handler on song list
    afx_msg void OnNMDblclkSongList(NMHDR *pNMHDR, LRESULT *pResult);
    afx_msg void OnLvnKeydownSongList(NMHDR *pNMHDR, LRESULT *pResult);
  	afx_msg void OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult);

    // User defined message handler
    // Main play dialog notify pl dialog which index is current playing song's
  	afx_msg LRESULT OnCurPlay(WPARAM wParam, LPARAM lParam);
    afx_msg LRESULT OnAddOneSong(WPARAM wParam, LPARAM lParam);
    afx_msg LRESULT OnStartDropFile(WPARAM wParam, LPARAM lParam);
    // Block ESC and Enter to prevent dialog exit
    BOOL PreTranslateMessage(MSG* pMsg);
    
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

	DECLARE_MESSAGE_MAP()

private:
    // Helper functions
    void FillSongList(int Idx);
    void InsertOneSongHelper(int PLIdx, int SongIdx, int GuiIdx);

    // CListCtrlEx call back functions
    static void GetSongTipsCallback(CListCtrl* List, unsigned int SongIdx,tstring & Tips);
    static void DropOneSongCallback(CListCtrl* List, const CString & FullPath, void * Param);
    static void DropOneItemCallback(CListCtrl* List, int SrcIdx, int DstIdx, void * Param);
    static void DropItemFinishCallback(CListCtrl* List, int StartRowIdx, int EndRowIdx);
    static void DropFileStartCallback(CListCtrl* List, int FilesNum);
    static void DropFileFinishCallback(CListCtrl* List, int StartRowIdx, int EndRowIdx, int FilesNum);
    // Notify main window to play the selected song
    void PlaySelSong();
    // Data member
    CComboBox m_PlayListSel;
    CListCtrlEx m_SongList;

    CMenuButton m_PLEdit;
    CMenuButton m_PLOperate;
    CMenuButton m_PlayMode;

    HANDLE m_ThreadHdler; 
};
